package com.merry.adventureRedis.bloomFilter.controller;


import com.merry.adventureRedis.bloomFilter.bean.Customer;
import com.merry.adventureRedis.bloomFilter.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping(value = "/customer/add")
    public void addCustomer() {
        for (int i = 0; i < 2; i++) {
            Customer customer = new Customer();
//            customer.setCname("customer" + i);
//            customer.setAge(new Random().nextInt(30) + 1);
//            customer.setPhone("139546556");
//            customer.setSex((byte)new Random().nextInt(2));
//            customer.setBirth(Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()));

            customerService.addCustomer(customer);
        }
    }

    @PostMapping(value = "/customer/{id}")
    public Customer findCustomerById(@PathVariable int id) {
        return customerService.findCustomerById(id);
    }

    @PostMapping(value = "/customerBloomFilter/{id}")
    public Customer findCustomerByIdWithBloomFilter(@PathVariable int id) {
        return customerService.findCustomerByIdWithBloomFilter(id);
    }
}